|
1
|
|
|
import {PageData} from '@enbock/application-router/Router'; |
|
2
|
|
|
import ListenerAdapter from '@enbock/state-value-observer/ListenerAdapter'; |
|
3
|
|
|
import {ObserverAdapter} from '@enbock/state-value-observer/ValueObserver'; |
|
4
|
|
|
import React from 'react'; |
|
5
|
|
|
import ApplicationView, {Adapter as ViewAdapter} from './View/Application'; |
|
6
|
|
|
import Model from './View/Application/Model'; |
|
7
|
|
|
import ApplicationPresenter from './View/Application/Presenter'; |
|
8
|
|
|
|
|
9
|
|
|
export interface ModulePageData extends PageData { |
|
10
|
|
|
module: string |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
export interface Adapter extends ViewAdapter { |
|
14
|
|
|
onPageChanged(newValue: PageData | null): void; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
export default class Application { |
|
18
|
|
|
private readonly adapter: Adapter; |
|
19
|
|
|
private readonly presenter: ApplicationPresenter; |
|
20
|
|
|
private view: ApplicationView | undefined; |
|
21
|
|
|
private readonly runCallback: () => void; |
|
22
|
|
|
|
|
23
|
|
|
constructor(adapter: Adapter, presenter: ApplicationPresenter) { |
|
24
|
6 |
|
this.presenter = presenter; |
|
25
|
6 |
|
this.adapter = adapter; |
|
26
|
6 |
|
this.runCallback = this.run.bind(this); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
attachToLanguage(adapter: ListenerAdapter<string>) { |
|
30
|
6 |
|
adapter.addListener(this.runCallback); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
attachToModuleState(adapter: ListenerAdapter<typeof React.Component | null>) { |
|
34
|
6 |
|
adapter.addListener(this.runCallback); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
attachToMenuOpenState(adapter: ObserverAdapter<boolean>) { |
|
38
|
6 |
|
adapter.onChange = this.runCallback; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
attachToContainerNode(containerNode: Element | DocumentFragment | null) { |
|
42
|
5 |
|
if (containerNode == null) return; |
|
43
|
4 |
|
this.view = new ApplicationView(containerNode, this.adapter); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
run() { |
|
47
|
7 |
|
if (this.view == undefined) return; |
|
48
|
|
|
|
|
49
|
4 |
|
const model: Model = this.presenter.present(); |
|
50
|
4 |
|
this.view.render(model); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|